class Solution(object):
    def longestAwesome(self, s):
        prefix = {0: -1}
        max_length = 0
        now_val = 0
        for index, c in enumerate(s):
            num = int(c)
            now_val ^= (1 << num)
            for j in range(10):
                last_val = now_val ^ (1 << j)
                if last_val in prefix:
                    max_length = max(max_length, index - prefix[last_val])
            if now_val in prefix:
                max_length = max(max_length, index - prefix[now_val])
            else:
                prefix[now_val] = index
        return max_length


data = Solution()
s = "3242415"
print(data.longestAwesome(s))
